package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.Plan;
import cn.wolfcode.crm.query.impl.PlanQuery;
import cn.wolfcode.crm.service.IPlanService;
import cn.wolfcode.crm.util.JSONResult;
import cn.wolfcode.crm.util.PageResult;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("plan")
public class PlanController {
    @Autowired
    IPlanService planService;

    @RequestMapping("view")
    @RequiresPermissions(value = {"plan:view","部门页面"},logical= Logical.OR)
    public String view() {
        return "plan";
    }

    @RequestMapping("cusplan")
    @RequiresPermissions(value = {"plan:view","部门页面"},logical= Logical.OR)
    public String cusplan() {
        return "cusplan";
    }

    @RequestMapping("getAll")
    @ResponseBody
    public List<Plan> getAll() {
        return planService.selectAll();
    }

    @RequestMapping("saveOrUpdate")
    @ResponseBody
    public JSONResult saveOrUpdate(Plan plan){
        try {
            planService.saveOrUpdate(plan);
        } catch (Exception e) {
            e.printStackTrace();
            return new JSONResult(false,"列表更新失败");
        }
        return new JSONResult(true,"恭喜您执行成功");
    }
    @RequestMapping("delete")
    @ResponseBody
    public JSONResult delete(Long id){
        try {
            planService.delete(id);
        } catch (Exception e) {
            e.printStackTrace();
            return new JSONResult(false,"列表更新失败");
        }
        return new JSONResult(true,"恭喜您执行成功");
    }
    @RequestMapping("cussaveOrUpdate")
    @ResponseBody
    public JSONResult cussaveOrUpdate(Plan plan){
        try {
            planService.cussaveOrUpdate(plan);
        } catch (Exception e) {
            e.printStackTrace();
            return new JSONResult(false,"列表更新失败");
        }
        return new JSONResult(true,"恭喜您执行成功");
    }

    @RequestMapping("setflag")
    @ResponseBody
    public JSONResult setflag(Plan plan){
        try {
            planService.setflag(plan);
        } catch (Exception e) {
            e.printStackTrace();
            return new JSONResult(false,"列表更新失败");
        }
        return new JSONResult(true,"恭喜您执行成功");
    }

    @RequestMapping("query")
    @ResponseBody
    public PageResult query(PlanQuery query){
        System.out.print(planService.query(query));
        return planService.query(query);
    }

}
